/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package negocio.CRUD;

import Vo.VoCompania;
import accesoDatos.negocio.DAOS.CompaniaDao;
import accesoDatos.negocio.entity.Compania;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author Beltran
 */
public class CRUDCompanias {
        CompaniaDao nuevo = new CompaniaDao();
        Compania entity = new Compania();
        public static EntityManagerFactory emf;
        public static EntityManager em;
    public CRUDCompanias(VoCompania vo){
        emf = Persistence.createEntityManagerFactory("parcialmlgPU", System.getProperties());
        em = emf.createEntityManager();
        entity.setId(vo.getId());
        entity.setName(vo.getName());
        entity.setSymbol(vo.getSymbol());
        entity.setDescription(vo.getDescription());}
    
        public String crearCompania(){
        return nuevo.create(entity,em);
        }
        public void borrarCompania(){
        nuevo.delete(entity, em);
        }
        public VoCompania buscarCompania(String name){
        entity = nuevo.buscarNombre(name, em);
        return entity.toVO();
        }
        public void actualizarCompania(String name){
        nuevo.update(name, entity, em);
        }
        
}
